﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Dominion.Core;
using Dominion.Core.Factories;
using System.Security.Principal;
using Dominion.Core.Runners;

namespace Dominion.Core
{
    public class Game
    {
        public Game(int nbPlayers, GameType gameType)
        {
            IList<Card> board = BoardFactory.Init(gameType);
            this.Board = new ObservableCollection<Card>(board);
            this.Trashed = new ObservableCollection<Card>();
            this.Players = new ObservableCollection<Player>();
            this.Id = new Guid();
            this.Messages = new FixedLengthQueue<string>(10);


            // Current 
            Players.Add(new Player(WindowsIdentity.GetCurrent().Name, this, new HumanStrategy()));

            // IA
            for (int i = 1; i < nbPlayers; i++)
            {
                Player p = new Player("IA " + i.ToString(), this, new JohnStrategy());
                Players.Add(p);
            }

         }

        public Guid Id { get; private set; }
        public ObservableCollection<Card> Board { get; private set; }
        public ObservableCollection<Card> Trashed { get; private set; }
        public ObservableCollection<Player> Players { get; private set; }
        public FixedLengthQueue<String> Messages { get; private set; }


        public void NextPlayer(Player p)
        {
            int nextPlayer = (Players.IndexOf(p) + 1) % Players.Count;
            Players[nextPlayer].BeginTurn();
        }


        public bool IsTerminated
        {
            get
            {
                return !Board.Where(c => c.Kind.Equals(Kind.Province)).Any();
            }
        }

    }


  
}


